package com.ruoyi.tws.feign;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ruoyi.tws.api.RemoteDriverClient;
import com.ruoyi.tws.api.domain.Driver;
import com.ruoyi.tws.service.IDriverService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/driver/client")
public class DriverClient implements RemoteDriverClient {

    @Autowired
    private IDriverService iDriverService;

    /**
     * 通过手机号获取司机
     * @param phone
     * @return
     */
    @PostMapping(value = "/getDriverByPhone")
    public Driver getDriverByPhone(@RequestParam("phone")String phone) {
       return iDriverService.getOne(new LambdaQueryWrapper<Driver>()
                                    .eq(Driver::getTelephone, phone));
    }

    /**
     * 司机注册
     * @param driver
     * @return
     */
    @PostMapping(value = "/regist")
    public boolean regist(@RequestBody Driver driver) {
        return iDriverService.regist(driver);
    }

}
